package klimuts.periodicals.catalog;

import java.util.Collection;
import java.util.LinkedList;

import klimuts.periodicals.user.Cart;

/**
 * Collection of {@link Periodical} objects, parent of {@link Cart}.<br>
 * Created for better compatibility any collections contains {@link Periodical} objects.<br>
 * Allow get an {@link Periodical} by it id without database accessing.
 * @author Siarhei Klimuts
 *
 */
public class Catalog extends LinkedList<Periodical> {  
	
	public Catalog() {
		super();
	}
	
	public Catalog(Collection<Periodical> c) {
		super(c);
	}
	
	/**
	 * Allow get an {@link Periodical} by id without database accessing.
	 * @param id - periodicals id
	 * @return {@link Periodical} if exists or <code>null</code> if not.
	 */
	public Periodical getPeriodical(long id){
		Periodical result=null;
		for (Periodical periodical: this)
			if (periodical.getId()==id) {
				result=periodical;
				break;
			}
		return result;
	}	

}
